﻿<%@ Page Language="C#" MasterPageFile="~/Admin.master" Theme="Admin" AutoEventWireup="true"
    CodeFile="AEditProduct.aspx.cs" Inherits="Pages_AEditProduct" Title="Untitled Page" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <div class="Popup">
        <div class="HeaderStyle">
            <span class="Title1">Category's editor</span>
            <div class="HeadLine">
            </div>
        </div>
        <div class="FormStyle">
            <div class="r1empty">
            </div>
            <table cellpadding="0" cellspacing="0" width="100%">
                <tr>
                    <td style="width: 100px;"> 
                        Code
                    </td>
                    <td class="c1empty">
                    </td>
                    <td>
                        <asp:TextBox ID="txtCode" runat="server" MaxLength="50" Width="200px"></asp:TextBox>
                        <asp:RequiredFieldValidator ID="rvalCode" runat="server" ValidationGroup="editProduct"
                            Display="Dynamic" ControlToValidate="txtCode">Phải nhập code</asp:RequiredFieldValidator>
                    </td>
                </tr>
                <tr class="r1empty">
                    <td colspan="3">
                    </td>
                </tr>
                <tr>
                    <td>
                        Tên
                    </td>
                    <td class="c1empty">
                    </td>
                    <td>
                        <asp:TextBox ID="txtName" runat="server" MaxLength="90" Width="200px"></asp:TextBox>
                        <asp:RequiredFieldValidator ID="rvalName" runat="server" ValidationGroup="editProduct"
                            Display="Dynamic" ControlToValidate="txtName">Phải nhập tên</asp:RequiredFieldValidator>
                    </td>
                </tr>
                <tr class="r1empty">
                    <td colspan="3">
                    </td>
                </tr>
                <tr>
                    <td>
                        Giá
                    </td>
                    <td class="c1empty">
                    </td>
                    <td>
                        <asp:TextBox ID="txtPrice" runat="server" MaxLength="30" Width="200px"></asp:TextBox>
                        <asp:RequiredFieldValidator ID="rvalPrice" runat="server" ValidationGroup="editProduct"
                            Display="Dynamic" ControlToValidate="txtPrice">Phải nhập giá</asp:RequiredFieldValidator>
                        <asp:CompareValidator ID="cpval" runat="server" ControlToValidate="txtPrice" Operator="DataTypeCheck"
                            Type="Integer" ValidationGroup="editProduct">Phải là số</asp:CompareValidator>
                    </td>
                </tr>
                <tr class="r1empty">
                    <td colspan="3">
                    </td>
                </tr>
                <tr>
                    <td>
                        Loại sản phẩm
                    </td>
                    <td class="c1empty">
                    </td>
                    <td>
                        <asp:DropDownList ID="dlCate" runat="server">
                        </asp:DropDownList>
                    </td>
                </tr>
                <tr class="r1empty">
                    <td colspan="3">
                    </td>
                </tr>
                <tr>
                    <td>
                        Trạng thái
                    </td>
                    <td class="c1empty">
                    </td>
                    <td>
                        <asp:DropDownList ID="dlStatus" runat="server">
                            <asp:ListItem Text="Enable" Value="Enable"></asp:ListItem>
                            <asp:ListItem Text="Disable" Value="Disable"></asp:ListItem>
                        </asp:DropDownList>
                    </td>
                </tr>
                <tr class="r1empty">
                    <td colspan="3">
                    </td>
                </tr>
                <tr>
                    <td valign="top">
                        Hình
                    </td>
                    <td class="c1empty">
                    </td>
                    <td>
                        <asp:TextBox ID="lbImage" Enabled="false" Width="200" runat="server"></asp:TextBox>
                        <input type="button" id="aUpImage" value="Choose file" class="marginleft10px" />
                        <input type="button" id="aViewImage" value="View image" class="marginleft10px" />
                        <asp:FileUpload ID="upFile" Width="200px" Style="display: none" runat="server" />
                    </td>
                </tr>
                <tr class="r1empty">
                    <td colspan="3">
                    </td>
                </tr>
                <tr>
                    <td valign="top">
                        Mô tả
                    </td>
                    <td class="c1empty">
                    </td>
                    <td>
                        <CKEditor:CKEditorControl ID="edDesc" Language="vi" Toolbar="Basic" runat="server"></CKEditor:CKEditorControl>
                    </td>
                </tr>
            </table>
            <div class="r20px">
            </div>
            <div class="ButtonStyle">
                <asp:Button ID="btSave" runat="server" Text="Save" CausesValidation="true" ValidationGroup="editProduct"
                    OnClick="btSave_Click" />
                <asp:Button ID="btSaveContinue" runat="server" Text="Save & Continue" CausesValidation="true"
                    ValidationGroup="editProduct" OnClick="btSaveContinue_Click" />
                    <asp:Button ID="btCancel" runat="server" Text="Cancel" CausesValidation="false"
                    OnClick="btCancel_Click" />
            </div>
            <asp:CustomValidator ID="cval" runat="server" ValidationGroup="editProduct" Display="Dynamic"></asp:CustomValidator>
        </div>
        <div class="FooterStyle">
        </div>
    </div>
    <div id="myviewimage">
        <asp:Image ID="viewImage" runat="server" title=""></asp:Image>
    </div>
    
    <script type="text/javascript" language="javascript">
        var editproduct = {
            init: function () {
                $("#myviewimage").hide();
                if ($('#<%= lbImage.ClientID %>').val().length == 0) {
                    $("#aViewImage").css("display", "none");
                }
                else {
                    $("#aViewImage").css("display", "");
                    $("#<%=viewImage.ClientID %>").attr("src", $('#<%= lbImage.ClientID %>').attr("imgsrc"));
                }
            },
            optViewImage: {
                onOpen: function (dialog) {
                    dialog.container.width(dialog.container.width() + 10);
                    dialog.container.height(dialog.container.height() + 10);
                    callback.slideDownToOpen(dialog, 400);
                },
                onClose: function (dialog) { callback.slideUpToClose(dialog, 400); },
                autoResize: false
            }
        };

        $(document).ready(function () {
            editproduct.init();
            if ($('#<%= lbImage.ClientID %>').text().trim().length > 0) {
                $('#aViewImage').show();
            }

            $("#aViewImage").bind("click", function () {
                $("#myviewimage").modal(editproduct.optViewImage);
            });

            $("#aUpImage").bind("click", function () {
                $('#<%= upFile.ClientID %>').click();
            });


            $('#<%= upFile.ClientID %>').change(function (e) {
                var file = e.target.files[0];
                if (file == undefined)
                    return;
                var reader = new FileReader();
                reader.onload = (function (theFile) {
                    return function (e) {
                        // Render thumbnail.
                        $("#<%=viewImage.ClientID %>").attr("src", e.target.result);
                    };
                })(file);
                reader.readAsDataURL(file);
                $('#aViewImage').css("display", "");
                $('#<%= lbImage.ClientID %>').val(file.name);
            });

        });

    </script>
</asp:Content>
